﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using Maticsoft.Common;

namespace WEB.compress
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                string folderFullName = Server.MapPath(@"~\document\compress");
                DirectoryInfo TheFolder = new DirectoryInfo(folderFullName);
                int i = 0; //i指定了列表的序号
                foreach (FileInfo NextFile in TheFolder.GetFiles())
                {
                    string strExten = System.IO.Path.GetExtension(NextFile.Name);
                    if (strExten == ".zip" || strExten == ".rar") //支持的格式
                    {
                        int index = NextFile.Name.LastIndexOf(".");
                        string fileName = NextFile.Name.Substring(0, index);
                        listKnow.Items.Add(fileName);
                        listKnow.Items[i].Value = Server.MapPath(@"~\document\compress\" + NextFile.Name);
                        i++;
                    }
                }
                if (i == 0) MessageBox.Show(this, "暂时没有相关文件，如果需要请先上传~");
            }
        }

        protected void listKnow_Click(object sender, BulletedListEventArgs e)
        {
            string fileName = listKnow.Items[e.Index].Value;
            //Response.Write("<script>window.document.location.href='/compress/CompressRead.aspx'</script>");
            Response.Redirect("~/compress/CompressRead.aspx?filename=" + Server.UrlEncode(fileName));
        }
    }
}